Document.readyState 您所在的位置:网站首页 document readystate 一直loading Document.readyState

Document.readyState

2024-06-03 14:47| 来源: 网络整理| 查看: 265

Summary

The Document.readyState property of a document describes the loading state of the document.

Values

The readyState of a document can be one of following:

loading The document is still loading. interactive The document has finished loading and the document has been parsed but sub-resources such as images, stylesheets and frames are still loading. complete The document and all sub-resources have finished loading. The state indicates that the load event is about to fire.

When the value of this property changes a readystatechange event fires on the document object.

Syntax var string = document.readyState; Examples Different states of readiness switch (document.readyState) { case "loading": // The document is still loading. break; case "interactive": // The document has finished loading. We can now access the DOM elements. var span = document.createElement("span"); span.textContent = "A element."; document.body.appendChild(span); break; case "complete": // The page is fully loaded. console.log("The first CSS rule is: " + document.styleSheets[0].cssRules[0].cssText); break; } readystatechange as an alternative to DOMContentLoaded event // alternative to DOMContentLoaded event document.onreadystatechange = function () { if (document.readyState === "interactive") { initApplication(); } } readystatechange as an alternative to load event // alternative to load event document.onreadystatechange = function () { if (document.readyState === "complete") { initApplication(); } } readystatechange as event listener to insert or聽modify the DOM before聽DOMContentLoaded // early manipulation of the document using an external script var bootstrap = function(evt){ if (evt.target.readyState === "interactive") { initLoader(); } else if (evt.target.readyState === "complete") { initApp(); } } document.addEventListener('readystatechange', bootstrap, false); Specification Specification Status Comment WHATWG HTML Living StandardThe definition of 'Document readiness' in that specification. Living Standard 聽 HTML 5.1The definition of 'Document readiness' in that specification. Recommendation 聽 HTML5The definition of 'Document readiness' in that specification. Recommendation Initial specification. Browser compatibility

Desktop Mobile

聽聽 Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari Basic support 5.0 (Yes) 4.0 4.0[3]8.0[1]聽9.0[2] 11.0[1] 5.0 聽聽 Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Basic support 2.2 (Yes) 4.0 9[2] 11.0[1] 5.0

[1] Only support聽'complete'.聽Opera Presto聽fire聽'complete'聽late聽after the 'load' event (in聽an聽incorrect order聽as per HTML5 standard specification).

[2] Internet Explorer 9 and 10聽have bugs where the聽'interactive' state can be fired too early before the document has finished parsing.

[3]聽When introduced with IE 4, the property was available for only the document, embed, img, link, object, script, and style objects. IE 5 expanded coverage to all HTML element objects.

See also readystatechange event DOMContentLoaded event load event


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有